package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.pojo.Employee;
import com.itheima.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangbin
 * @date 2022/6/8 16:21
 * 员工表现层
 */
@RestController
@RequestMapping(value = "employee", produces = "application/json;charset=utf-8")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    /**
     * 登录
     *
     * @param employee 接收username password的json对象
     * @return
     */
    @PostMapping(value = "/login")
    R<Employee> login(@RequestBody Employee employee) {
        Employee result = employeeService.login(employee);
        R<Employee> flag = result!=null?R.success(employee):R.error("登录失败，请输入正确的账号密码");

        return new R<Employee>(flag.getCode(),flag.getMsg(),result,flag.getMap());

    }
}
